package com.example.demo.four;

import java.text.SimpleDateFormat;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;

public class participant1 extends Message {
    public participant1(String name, int speed, ExecutorService executor, CyclicBarrier barrier) {
        super(name, speed, executor, barrier);
    }

    public participant1(String name, int speed, ExecutorService executor) {
        super(name, speed, executor);
    }

    @Override
    public void run() {
        try {
            barrier.await();
        } catch (Exception e1) {

        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(sdf.format(System.currentTimeMillis()));
        while (!FINISH) {
            System.out.println(this.name + ":我的速度是：" + this.speed + "m/s，我游了" + this.now + "m这么多了");
            try {
                Thread.sleep(1000);
                if (now % 10 == 0) {
                    Thread.sleep(1000);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            now += speed;
            finish();
        }
    }
}
